package com.advertisementsystem.Mapper;

import com.advertisementsystem.entity.Advertisement;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;


@Mapper
public interface AdvertisementMapper extends BaseMapper<Advertisement> {
    @Select("SELECT COUNT(*) FROM advertisement " +
            "WHERE advertiser_id = #{advertiserId} AND status = 2")
    int countActiveAds(@Param("advertiserId") Long advertiserId);

    @Select("SELECT * FROM advertisement " +
            "WHERE advertiser_id = #{advertiserId} " +
            "ORDER BY created_time DESC LIMIT 5")
    List<Advertisement> selectRecentAds(@Param("advertiserId") Long advertiserId);
}
